package com.example.android;


import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import com.example.myapplication.NewsAdapter;
import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private String[] titles={
            "三菱电机覅收到，非技术类飞机斯蒂芬",
            "世界里覅大祭司，伺机待发类似的就覅了上帝",
            "开始，十九分零四的封建时代，是解放螺丝钉解放四点",
            "撒发射点发撒旦发射点发生发，十分士大夫十分低调。",
            "世界里覅大祭司，伺机待发类似的就覅了上帝",
            "睡觉了房间斯蒂芬，书法家拉斯附近的思路，四点九六",
            "小雏菊小两口吵架，上了腹肌撕裂的房间数量大幅，伺机待发类似的就覅"
    };
    private String[] names={
            "撒旦发射点士大夫","沙发舒服的","是发发士大夫撒旦","两款手机佛i的","世界里覅上帝就发四点","老师的军阀势力的飞机设计的法理上的"
    };
    private String[] comments={
            "98777评","18评","180评","58评","67评","900评"
    };
    private String[] times={
            "6小时前","3小时前","68小时前","33小时前","7小时前","1小时前"
    };
    private int[] icons1={
            R.drawable.food,R.drawable.takeout,R.drawable.e_sports
    };
    private int[] icons2={
            R.drawable.sleep1,R.drawable.sleep2,R.drawable.sleep3,
            R.drawable.fruit1,R.drawable.fruit2,R.drawable.fruit3
    };

    private int[] types={1,1,2,1,2,1};
    private RecyclerView mRecyclerView;
    private NewsAdapter mAdapter;
    private List<com.example.android.NewsBean> NewsList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setData();
        mRecyclerView=findViewById(R.id.rv_list);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter=new NewsAdapter(MainActivity.this,NewsList);
        mRecyclerView.setAdapter(mAdapter);
    }

    private void setData(){
        NewsList=new ArrayList<com.example.android.NewsBean>();
       com.example.android.NewsBean bean;
        for(int i=0;i<titles.length;i++){
            bean=new com.example.android.NewsBean();
            bean.setId(i+1);
            bean.setTitle(titles[i]);
            bean.setName(names[i]);
            bean.setComment(comments[i]);
            bean.setTime(times[i]);
            bean.setType(types[i]);
            switch (i){
                case 0:
                    List<Integer> imgList0=new ArrayList<>();
                    bean.setImgList(imgList0);
                    break;
                case 1:
                    List<Integer> imgList1=new ArrayList<>();
                    imgList1.add(icons1[i-1]);
                    bean.setImgList(imgList1);
                    break;
                case 2:
                    List<Integer> imgList2=new ArrayList<>();
                    imgList2.add(icons2[i-2]);
                    imgList2.add(icons2[i-1]);
                    imgList2.add(icons2[i]);
                    bean.setImgList(imgList2);
                    break;
                case 3:
                    List<Integer> imgList3=new ArrayList<>();
                    imgList3.add(icons1[i-2]);
                    bean.setImgList(imgList3);
                    break;
                case 4:
                    List<Integer> imgList4=new ArrayList<>();
                    imgList4.add(icons2[i-1]);
                    imgList4.add(icons2[i]);
                    imgList4.add(icons2[i+1]);
                    bean.setImgList(imgList4);
                    break;
                case 5:
                    List<Integer> imgList5=new ArrayList<>();
                    imgList5.add(icons1[i-3]);
                    bean.setImgList(imgList5);
                    break;
            }
            NewsList.add(bean);
        }
    }
}


